1 package org.apache.lucene.analysis.ja.dict;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 import java.io.IOException;
21
22 import org.apache.lucene.analysis.ja.TestJapaneseTokenizer;
23 import org.apache.lucene.util.LuceneTestCase;
24 import org.junit.Test;
25
26 public class UserDictionaryTest extends LuceneTestCase {
27
28 @Test
29 public void testLookup() throws IOException {
30 UserDictionary dictionary = TestJapaneseTokenizer.readDict();
31 String s = "関西国際空港に行った";
32 int[][] dictionaryEntryResult = dictionary.lookup(s.toCharArray(), 0, s.length());
33
34 assertEquals(3, dictionaryEntryResult.length);
35
36
37 assertEquals(0, dictionaryEntryResult[0][1]);
38 assertEquals(2, dictionaryEntryResult[1][1]);
39 assertEquals(4, dictionaryEntryResult[2][1]);
40
41
42 assertEquals(2, dictionaryEntryResult[0][2]);
43 assertEquals(2, dictionaryEntryResult[1][2]);
44 assertEquals(2, dictionaryEntryResult[2][2]);
45
46 s = "関西国際空港と関西国際空港に行った";
47 int[][] dictionaryEntryResult2 = dictionary.lookup(s.toCharArray(), 0, s.length());
48
49 assertEquals(6, dictionaryEntryResult2.length);
50 }
51
52 @Test
53 public void testReadings() throws IOException {
54 UserDictionary dictionary = TestJapaneseTokenizer.readDict();
55 int[][] result = dictionary.lookup("日本経済新聞".toCharArray(), 0, 6);
56 assertEquals(3, result.length);
57 int wordIdNihon = result[0][0];
58 assertEquals("ニホン", dictionary.getReading(wordIdNihon, "日本".toCharArray(), 0, 2));
59
60 result = dictionary.lookup("朝青龍".toCharArray(), 0, 3);
61 assertEquals(1, result.length);
62 int wordIdAsashoryu = result[0][0];
63 assertEquals("アサショウリュウ", dictionary.getReading(wordIdAsashoryu, "朝青龍".toCharArray(), 0, 3));
64 }
65
66 @Test
67 public void testPartOfSpeech() throws IOException {
68 UserDictionary dictionary = TestJapaneseTokenizer.readDict();
69 int[][] result = dictionary.lookup("日本経済新聞".toCharArray(), 0, 6);
70 assertEquals(3, result.length);
71 int wordIdKeizai = result[1][0];
72 assertEquals("カスタム名詞", dictionary.getPartOfSpeech(wordIdKeizai));
73 }
74
75 @Test
76 public void testRead() throws IOException {
77 UserDictionary dictionary = TestJapaneseTokenizer.readDict();
78 assertNotNull(dictionary);
79 }
80 }